console.log("11"); 
console.log(document.querySelector("#demo2"));
document.querySelector("#demo2").addEventListener("click", function () {
    let a = $("#demo").val();
    let b = $("#demo1").val();
    let json = { "method": "unzip", "filePath": a, "targetPath": b };
    if (a == "" || b == "") {
        alert("请填写完整所有输入框")
    } else {
        $.ajax({
            url: './json/unzip.json',
            type: 'GET',
            dataType: 'json',
            data: json,
            cache: false,
            success: function (dat) {
                    returnColumn2(dat);
            },
            error: function () {
                alert('服务器超时，请重试！');
            }
        });
    }
}) 
//压缩ajax
document.querySelector("#formal3").addEventListener("click", function () {
    let a = $("#formal").val();
    let b = $("#formal2").val();
    let c = $("#formal7").val();
    if (a == "" || b == "" || c == "") {
        alert("请填写完整所有输入框")
    } else {
        let json = { "method": "zip", "filePath": a, "targetPath": b, "format": c };
        $.ajax({
            url: './json/unzip.json',
            type: 'GET',
            dataType: 'json',
            date: json,
            cache: false,
            success: function (dat) {
                if (json.name == "" || json.formate == "") {
                    alert("请输入完整输入框")
                } else {    
                    returnColumn(dat);
                }
            },
            error: function () {
                alert('服务器超时，请重试！');
            }
        });

    }
})


//显示切换
let thisnode1 = document.querySelector("#compress");
let thisnode2 = document.querySelector("#uncompress");
document.querySelector("#switch").addEventListener("click", function () {
    let thisnode = document.querySelector("#compress");
    thisnode.parentNode.appendChild(thisnode2);
    thisnode.parentNode.removeChild(thisnode);
    thisnode2.style.display = "block";
})
document.querySelector("#unswitch").addEventListener("click", function () {
    let thisnode = document.querySelector("#uncompress");
    thisnode.parentNode.appendChild(thisnode1);
    thisnode.parentNode.removeChild(thisnode);
    thisnode1.style.display = "block";
})

//zip
function returnColumn(dat) {
    let a = document.createElement("li");
    a.innerHTML="收到的目录的数据：</br>";
    document.querySelector("#formal6").appendChild(a); 
    for(let key in dat){
        let flag=typeof dat[key];
        if(flag == "object"){
            for(let value in dat[key]){
                let a = document.createElement("li");
                a.innerHTML = dat[key][value];
                document.querySelector("#formal6").appendChild(a);            
            }
        }else{
            let a = document.createElement("li");
            a.innerHTML = dat[key];
            document.querySelector("#formal6").appendChild(a);
        }
    }
}
//unzip模块
function returnColumn2(dat) {
    let a = document.createElement("li");
    a.innerHTML="收到的目录的数据：</br>";
    document.querySelector("#note").appendChild(a); 

    for(let key in dat){
        let flag=typeof dat[key];
        if(flag == "object"){
            for(let value in dat[key]){
                let a = document.createElement("li");
                a.innerHTML = dat[key][value];
                document.querySelector("#note").appendChild(a);            
            }
        }else{
            let a = document.createElement("li");
            a.innerHTML = dat[key];
            document.querySelector("#note").appendChild(a);
        }
    }
}
